package service

import (
	"github.com/gin-gonic/gin"
	"mojieshi/define"
	"mojieshi/models"
	"net/http"
)

type PayJson struct {
	ID      int    `gorm:"type:int(10); primaryKey" json:"id"`
	Aid     int    `gorm:"type:int(10);"json:"aid"`
	Type    int    `gorm:"type:int(10);" json:"type"` //支付方式：1现金 2余额
	Name    string `json:"name"`                      //支付名称
	SubName string `json:"sub_name"`                  //备注名称
	Pic     string `json:"pic"`
}

// 获取支付列表
func PayList(c *gin.Context) {
	var jsonData models.MPaySet
	err := c.ShouldBindJSON(&jsonData)
	if err != nil {
		define.Response.ResultFail(c, 10000, define.JsonDataX, "")
		return
	}
	var list []PayJson
	var conut int64
	tx := models.DB.Model(new(models.MPaySet)).Where("state=? AND aid=?", jsonData.State, jsonData.Aid)
	if jsonData.ID > 0 {
		tx = tx.Where("id=?", jsonData.ID)
	}
	tx = tx.Count(&conut).Find(&list)
	if tx.Error != nil {
		define.Response.ResultFail(c, 10000, define.JsonDataX, "")
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"code":    0,
		"data": map[string]interface{}{
			"list":  list,
			"count": conut,
		},
	})
}
